
<template>
  <div>

      <avue-input-tree default-expand-all
                       v-bind:multiple="(column.multiple||column.multipleTest) ? 'multiple' : null"
                       v-model="currentValue"
                       :disabled="isDisabled"
                       placeholder="选择部门"
                       :dic="data"></avue-input-tree>
  </div>
</template>

<script>
  import {fetchOrgTree} from '@/framework-core/api/user.js';
  import { convertDic} from '@/framework-core/utils/util'
  export default {
    name: 'orgTreeChoose',
    props: ['column','modelValue'],
    inject: ['getViewFormData'],
    data() {
      return {
        form: {},
        currentValue: null,
        data: [],
      }
    },
    mounted(){
      if( this.getViewFormData){
        this.formData = this.getViewFormData()
      }
    },
      computed: {
          isDisabled: function () {
            // if(!this.column){
            //     return true;
            // }
            return this.column.disabled;
          }
      },

    watch: {
      currentValue(newVal) {
        let  newValStr = newVal;
        if(this.column.multiple||this.column.multipleTest){
          newValStr =newVal?newVal.join(","):[];
        }
        this.$emit('update:modelValue', newValStr);
      },
      modelValue: {
        immediate: true,   //
        deep: true,
        handler(newVal, oldVal) {
          if(this.column.multiple||this.column.multipleTest){
            this.currentValue = newVal?newVal.split(","):[];
          }else {
            this.currentValue = newVal;
          }
          //alert(this.column.multiple+":"+JSON.stringify(  this.currentValue))
         // this.currentValue = newVal;
        }
      }
    },
    created() {
        this.initData();
    },

    methods: {

        initData() {

            fetchOrgTree().then(response => {
                this.data = []
                const menu = {value:'', label: "请选择部门", children: []};
                convertDic(response.data.data.data, menu.children,true);
                this.data.push(menu);

            });
        }
    }

  };
</script>

<style >
  /*.el-form-item__content{*/
  /*  margin-left: 0px!important;*/
  /*}*/
</style>

<style lang="scss">

</style>
